<template>
  <!--  底部导航-->
  <router-view/>
  <div id="nav">
    <router-link class="tab-bar-item" to="/">
      <div><i class="iconfont icon-shouye"></i></div>
      <div>首页</div>
    </router-link>
    <router-link class="tab-bar-item" to="/category">
      <div><i class="iconfont icon-fenlei"></i></div>
      <div>分类</div>
    </router-link>
    <router-link class="tab-bar-item" to="/shopcart">
      <van-badge :content="$store.state.cartCount">
        <i class="iconfont icon-gouwuche"></i>
      </van-badge>
      <div>购物车</div>
    </router-link>
    <router-link class="tab-bar-item" to="/profile">
      <div><i class="iconfont icon-wode"></i></div>
      <div>我的</div>
    </router-link>
  </div>
</template>

<script>
import {onMounted} from "vue";
import {useStore} from "vuex";
export default {
  setup() {
    const store = useStore()
    // 登录用户更新购物车数量
    onMounted(() => store.state.user.isLogin && store.dispatch('updateCart'))
  }
}
</script>

<style lang="scss">
@import "~assets/css/base.css";

#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}

#nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 50px;
  background: #f6f6f6;
  box-shadow: 0 -3px 1px rgba(100, 100, 100, 0.1);
  z-index: 99;
  display: flex;
  justify-content: space-around;
  align-items: center;

  a {
    color: var(--color-text);

    &.router-link-exact-active {
      color: var(--color-tint);
    }
  }

  .tab-bar-item {
    font-size: var(--font-size);
  }
}
</style>
